
using System;
using System.Collections;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.DataTier.Source;

namespace OR.Lazarus.Library.DataTier.Source.Lazarus
{
   public class ConstraintCollection : EntityCollectionBase
   {
		public virtual void Add( Derived.ConstraintDetail pSource )
		{
			this.List.Add( pSource );

			if ( pSource.ParentCollection == null )
			{
				pSource.ParentCollection	= ( Derived.ConstraintCollection )this;
			}
			
			if ( pSource.ParentEntity == null )
			{
				pSource.ParentEntity			= this.ParentEntity;
			}
		}

		public virtual void AddAt( Int32 pIndex, Derived.ConstraintDetail pSource )
		{
			this.List.Insert( pIndex, pSource );

			pSource.ParentCollection	= ( Derived.ConstraintCollection )this;
			pSource.ParentEntity			= this.ParentEntity;
		}
		
		public virtual void AddRange( Derived.ConstraintDetail[] pSource )
		{
			foreach ( Derived.ConstraintDetail vSource in pSource )
			{
				this.Add( vSource );
			}
		}
		
		public new Derived.ConstraintDetail this[ int p_iIndex ]
		{
			get
			{
				return ( Derived.ConstraintDetail )base[ p_iIndex ];
			}
		}
		
				
		public virtual void LoadXml( XmlElement p_oSource )
		{
			Derived.ConstraintDetail v_oNew;
			
			foreach ( XmlElement v_elCurrent in p_oSource.SelectNodes( "lz:constraint", PersistenceConfig.Namespaces ) )
			{
				v_oNew = new Derived.ConstraintDetail();
				
				v_oNew.LoadXml( v_elCurrent );

				this.Add( v_oNew );
			}
		}
		
		public virtual XmlElement SaveXml( XmlDocument p_oDocument )
		{
			if ( this.List.Count > 0 )
			{
				XmlElement	v_elNew	= p_oDocument.CreateElement( "lz", "constraints", "http://schemas.icitadel.com/Lazarus/Source.xsd" );
				
				foreach ( Derived.ConstraintDetail v_oCurrent in this.List )
				{
					v_elNew.AppendChild( v_oCurrent.SaveXml( p_oDocument ) );
				}
				
				return ( v_elNew );
			}
			else
			{
				return ( null );
			}
		}
   }
}
   